package com.lieve.servicea.controller;

import com.lieve.servicea.entity.Article;
import com.lieve.servicea.service.ArticleService;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author sunlijiang
 * @date 2020/2/22
 */
@Controller
@RequestMapping("/article")
public class ArticleController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Resource
    private ArticleService articleService;

    @RequestMapping("/articleList.html")
    public String getArticleList(Model model, String title, @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam(defaultValue = "1") Integer pageNum) {
        int offset = (pageNum - 1) * pageSize;
        List<Article> list = articleService.getArticleList();
        model.addAttribute("list", list);
        return "article/articleList";
    }

    @ResponseBody
    @RequestMapping("/{redis}/{value}")
    public String redisSet(@PathVariable String redis, @PathVariable String value) {
        stringRedisTemplate.opsForValue().set(redis, value);
        return "OK";
    }


}
